var router = require('koa-router')();

//筹款项目查询
router.post('/asset/list',async (ctx, next)=>{
    let {
    	pageNumber=1,
    	pageSize=10,
    	asset_status,
    	keyword="",
        list_type,
        debtor="",
        creditor="",
        level="",
        settled="",
        start_date="",
        end_date="",

    } = ctx.request.body;

    console.log('asset_status------------',pageNumber);
    console.log('asset_status------------',pageSize);
    console.log('asset_status------------',asset_status);
    console.log('asset_status------------',keyword);
    console.log('asset_status------------',list_type);
    console.log('asset_status------------',debtor);
    console.log('asset_status------------',creditor);
    console.log('asset_status------------',level);
    console.log('asset_status------------',settled);
    console.log('asset_status------------',start_date);
    console.log('asset_status------------',end_date);
    let result = await ctx.get('/web/asset/list',{
			    	pageNumber,
			    	pageSize,
			    	asset_status,
			    	keyword,
                    list_type,
                    debtor,
                    creditor,
                    level,
                    settled,
                    start_date,
                    end_date,

			    });
	ctx.body = result;
});


//提交资产
router.post('/submit',async(ctx,next) =>{
	let {assetStatusType,asset_id_list} = ctx.request.body;
    console.log('assetStatusType========',assetStatusType);
    let result = await ctx.post('/web/asset/change-status',{assetStatusType,asset_id_list});
    ctx.body = result;
})

/**   资产详情相关  start **/

//顶部信息
router.post('/top-detail' , async (ctx,next) => {
    let {id} = ctx.request.body;
    ctx.body = await ctx.get('/web/asset/top-info',{id});
});
//基础信息
router.post('/basic-info' , async (ctx,next) => {
    let {id} = ctx.request.body;
    ctx.body  = await ctx.get('/web/asset/basic-info' ,{id});
});
//编辑基础信息
router.post('/basic-info/edit' , async (ctx,next) => {
    let {
        deposited,
        deposited_files,
        expanded,
        expanded_files,
        guarantee,
        guarantee_files,
        id,
        insurance_coverage,
        insured,
        insured_files,
        level,
        money_deposited
    } = ctx.request.body;
    ctx.body = await ctx.post('/web/asset/detail/update-basic-info' , {
        deposited:deposited==1,
        deposited_files,
        expanded:expanded==1,
        expanded_files,
        guarantee,
        guarantee_files,
        id,
        insurance_coverage,
        insured:insured==1,
        insured_files,
        level,
        money_deposited
    })
})
//上下游合同
router.post('/contract-detail' , async (ctx,next) => {
    let {id,contract_type} = ctx.request.body;
    ctx.body = await ctx.get('/web/asset/contract-detail',{id,contract_type});
});
//编辑上下游合同
router.post('/contract/edit' , async (ctx,next) => {
    let {
        amount,
        asset_id,
        buyer,
        consigned,
        consigned_files,
        consignee,
        delivered,
        delivered_files,
        deliverer,
        expire_date,
        files,
        goods_type,
        id,
        number,
        reckoned,
        reckoned_files,
        reckoner,
        seller,
        sign_date,
        supply_end_date,
        supply_start_date,
        transport_type,
        unit_price
    } = ctx.request.body;
    ctx.body = await ctx.post('/web/asset/detail/update-contract' ,{
        amount,
        asset_id,
        buyer,
        consigned:consigned==1,
        consigned_files,
        consignee,
        delivered:delivered==1,
        delivered_files,
        deliverer,
        expire_date,
        files,
        goods_type,
        id,
        number,
        reckoned:reckoned==1,
        reckoned_files,
        reckoner,
        seller,
        sign_date,
        supply_end_date,
        supply_start_date,
        transport_type,
        unit_price
    })
})


//货权信息
router.post('/property-ownership-detail' , async (ctx,next) => {
    let {id} = ctx.request.body;
    ctx.body = await ctx.get('/web/asset/property-ownership-detail' ,{id});
})
//编辑货权信息
router.post("/propertyOwnership/edit", async (ctx,next) => {
    let {
        amount,
        asset_id,
        cert_files,
        delivery_start_date,
        delivery_end_date,
        id,
        laboratory_files,
        property_files,
        sheet_files,
        tool_files,
        transfer_date,
        transport_files,
        unit_price,
        usage
    } = ctx.request.body;
    console.log(delivery_start_date , '-----',delivery_end_date)
    ctx.body = await ctx.post("/web/asset/detail/update-property-ownership",{
        amount,
        asset_id,
        cert_files,
        delivery_start_date,
        delivery_end_date,
        id,
        laboratory_files,
        property_files,
        sheet_files,
        tool_files,
        transfer_date,
        transport_files,
        unit_price,
        usage
    })
})


/**  发票相关 start **/
//发票信息
router.post('/receipt/list' , async (ctx,next) => {
    let {id} = ctx.request.body;
    let receipt  = await ctx.get('/web/asset/receipt-list' ,{id});
    ctx.body = receipt;
});
//添加发票
router.post('/receipt/edit' , async (ctx,next) => {
    let {
        amount,
        asset_id,
        date,
        files,
        money,
        number,
        id
    } = ctx.request.body;
    let params ={amount,asset_id,date,files,money,number};
    let result = null;
    if(id){
        params.id = id;
        result = await ctx.post('/web/asset/detail/update-receipt',params)
    }else {
        result = await ctx.post('/web/asset/detail/add-receipt',params);
    }
    ctx.body = result;
});
//发票详情
router.post('/receipt/detail' , async (ctx,next) => {
    let {id} = ctx.request.body ;
    ctx.body = await ctx.get('/web/asset/detail/receipt-detail',{id});
})

//删除发票
router.post('/receipt/delete' , async (ctx,next) => {
    let {id} = ctx.request.body;
    ctx.body = await ctx.post('/web/asset/detail/delete-receipt' ,{id});
})

/**  发票相关 end **/

/**  结算相关 start **/
//结算信息
router.post('/settleAccount/list' , async (ctx,next) => {
    let {id} = ctx.request.body;
    ctx.body = await ctx.get('/web/asset/settle-account-list' ,{id});
});
//结算信息添加或修改
router.post('/settleAccount/edit' , async (ctx,next) => {
    let {
        asset_id,
        amount,
        date,
        files,
        unit_price,
        money,
        id
    } = ctx.request.body;
    let params ={
        asset_id,
        amount,
        date,
        files,
        unit_price,
        money
    };
    let result = null;
    if(id){
        params.id = id;
        result = await ctx.post('/web/asset/detail/update-settle-account',params)
    }else {
        result = await ctx.post('/web/asset/detail/add-settle-account',params);
    }
    ctx.body = result;
});
//结算详情
router.post('/settleAccount/detail' , async (ctx,next) => {
    let {id} = ctx.request.body ;
    ctx.body = await ctx.get('/web/asset/detail/settle-account-detail',{id});
})
//删除结算
router.post('/settleAccount/delete' , async (ctx,next) => {
    let {id} = ctx.request.body;
    ctx.body = await ctx.post('/web/asset/detail/delete-settle-account' ,{id});
})
/**  结算相关 end **/

/** 回款相关  start **/
//回款信息
router.post('/retrunMoney/list' , async (ctx,next) => {
    let {id} = ctx.request.body;
    ctx.body = await ctx.get('/web/asset/fund-restream-list' ,{id});
});
//回款信息添加或修改
router.post('/retrunMoney/edit' , async (ctx,next) => {
    let {
        asset_id,
        date,
        expire_date,
        files,
        money,
        note_money,
        type,
        id
    } = ctx.request.body;
    let params ={
        asset_id,
        date,
        expire_date,
        files,
        money,
        note_money,
        type
    };
    let result = null;
    if(id){
        params.id = id;
        result = await ctx.post('/web/asset/detail/update-fund-restream',params)
    }else {
        result = await ctx.post('/web/asset/detail/add-fund-restream',params);
    }
    ctx.body = result;
});
//回款详情
router.post('/retrunMoney/detail' , async (ctx,next) => {
    let {id} = ctx.request.body ;
    ctx.body = await ctx.get('/web/asset/detail/fund-restream-detail',{id});
})
//删除回款
router.post('/retrunMoney/delete' , async (ctx,next) => {
    let {id} = ctx.request.body;
    ctx.body = await ctx.post('/web/asset/detail/delete-fund-restream' ,{id});
})
/** 回款相关  end **/

/**  其他信息 start **/

//其他信息
router.post('/remark/list' , async (ctx,next) => {
    let {id} = ctx.request.body;
    ctx.body = await ctx.get('/web/asset/remark-list' ,{id});
});
//其他信息添加或修改
router.post('/remark/edit' , async (ctx,next) => {
    let {
        asset_id,
        fee_date,
        detail,
        files,
        fee_money,
        type,
        id
    } = ctx.request.body;
    let params ={
        asset_id,
        fee_date,
        detail,
        files,
        fee_money,
        type,
    };
    console.log('/web/asset/detail/update-remark',params);
    let result = null;
    if(id){
        params.id = id;
        result = await ctx.post('/web/asset/detail/update-remark',params)
    }else {
        result = await ctx.post('/web/asset/detail/add-remark',params);
    }
    ctx.body = result;
});
//其他详情
router.post('/remark/detail' , async (ctx,next) => {
    let {id} = ctx.request.body ;
    ctx.body = await ctx.get('/web/asset/detail/remark-detail',{id});
})
//删除回款
router.post('/remark/delete' , async (ctx,next) => {
    let {id} = ctx.request.body;
    ctx.body = await ctx.post('/web/asset/detail/delete-remark' ,{id});
})
/**  其他信息 end **/

/**   资产详情相关  start **/

export default router;
